<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,member-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="css/pagination.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>商家中心</title>
</head>
<body>

	<nav class="breadcrumb">
			<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商家中心 <span class="c-gray en">&gt;</span> 商户品类

			<a class="btn btn-refresh btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" onclick="javascript:location.replace(location.href);" >刷新</a>
	</nav>
	<div class="pd-20">
		<div>
		<form action="<%=path%>/backstage/findbycnamefzy" method="get" class="form form-horizontal" id="form-type-add">
			<div class="row cl">
					<label class="form-label col-1">所属品类：</label>
					<div class="formControls col-2"> 
						<span class="select-box">
							<select class="select" name="type1" id="type1" onchange="firstChange(this);">
								<option value="-1">--大类--</option>
								<c:forEach items="${types1}" var="type">
									<option value="${type.cCode}" <c:if test="${type.cCode==conditions.type1}">selected</c:if> >${type.cName}</option>
								</c:forEach>
							</select>
						</span>
		   			</div>
				   <div class="formControls col-2"> <span class="select-box">
						<select class="select" id="type2"  name="type2" onchange="secondChange(this);">
							<option value="-1">--中类--</option>
							<c:forEach items="${types2}" var="type">
							<option value="${type.cCode}" <c:if test="${type.cCode==conditions.type2}">selected</c:if> >${type.cName}</option>
							</c:forEach>
						</select>
						</span>
				   </div>
				</div>
				<div class="mt-10"></div>
			<label class="form-label col-1" >所属分站：</label>
					<div class="formControls col-2">
					<span class="select-box">
					<select name="city_id" class="select">
						<option value="">默认</option>
						<c:forEach items="${citys}" var="city">
						<option value="${city.id}" <c:if test="${city.id==conditions.city_id}">selected</c:if>>${city.name}</option>
						</c:forEach>
					</select>
					</span>
					</div>
			<label class="form-label col-1">品类名称：</label>
			<div class="formControls col-2">
			<input type="text" class="input-text" placeholder="" id="" name="cName2" value="${conditions.cName}"/>
			</div>
			<label class="form-label col-1">店铺名称：</label>
			<div class="formControls col-2">
			<input type="text" class="input-text" placeholder="" id="" name="shopName" value="${conditions.shopName}"/>
			</div>
			<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont"></i> 查询</button>
			<a class="btn btn-danger radius" onclick="type_reset('<%=path%>/backstage/shops_type-list')" href="javascript:;"><i class="Hui-iconfont"></i> 重置</a>
			<a class="btn btn-primary radius" onclick="type_add('添加品类','<%=path%>/backstage/type-add-pre')" href="javascript:;"><i class="Hui-iconfont"></i> 添加品类</a>
		</form>
		</div>
		<div class="mt-20">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>
					<tr class="text-c">
						<th width="40">ID</th>
						<th>大类</th>
						<th>中类</th>
						<th>小类</th>
						<th>来源</th>
						<th>更新时间</th>
						<th>更新人</th>
						<th>排序</th>
						<th>是否有效</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<tbody>
						<c:forEach items="${types}" var="type">		
						<tr class="text-c">
							<input type="hidden" id="cCode" name="cCode"
								value='${type.cCode}' />
							<td>${type.cCode}</td>
							<c:if test="${type.cBelong==0&&type.cGrade==0}">
								<td>${type.cName}</td>
								<td>---</td>
								<td>---</td>
							</c:if>
							<c:if test="${type.cBelong==type.cGrade&&type.cGrade!=0}">
								<td>
								<c:forEach items="${alltypes}" var="type2">
									<c:if test="${type2.cCode==type.cBelong}">
										${type2.cName}
									</c:if>
								</c:forEach>
								</td>
								<td>
								${type.cName}
								</td>
								<td>---</td>
							</c:if>
							<c:if test="${type.cBelong!=type.cGrade&&type.cGrade!=0&&type.cBelong!=0}">
								<td>
								<c:forEach items="${alltypes}" var="type2">
									<c:if test="${type2.cCode==type.cGrade}">
										${type2.cName}
									</c:if>
								</c:forEach>
								</td>
								<td>
								<c:forEach items="${alltypes}" var="type2">
									<c:if test="${type2.cCode==type.cBelong}">
										${type2.cName}
									</c:if>
								</c:forEach>
								</td>
								<td>${type.cName}</td>
							</c:if>
							<td>${type.sources}</td>
							<td>${type.updatetime}</td>
							<td>${type.updateuser}</td>
							<td>${type.cSort}</td>
							<td>
							<c:choose>
								<c:when test="${1==type.cEnable}">
									<span class="label label-success radius">有效</span>
								</c:when>
								<c:otherwise>
									<span class="label label-warning radius">已删除</span>
								</c:otherwise>
							</c:choose>
							</td>
							<td class="td-manage">
								<a style="text-decoration:none"
								onClick="type_edit(this,'${type.cCode}')" href="javascript:;"
								title="编辑">编辑</a>
								&nbsp;&nbsp;&nbsp;&nbsp;
								<a style="text-decoration:none"
								onClick="type_disable(this,'${type.cCode}')" href="javascript:void(0);"
								title="删除">删除${typs.size }</a>
								
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<div id="Pagination" class="page-con"></div>
		</div>
	</div>
	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script>
	<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
	<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript"
		src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="js/H-ui.js"></script>
	<script type="text/javascript" src="js/H-ui.admin.js"></script>
	<script type="text/javascript" src="js/jquery.pagination.js"></script>
	<script type="text/javascript">
	$(function() {
		initPager();
	});
	
	var showCount = ${pageInfo.showCount};
	var currentPage = ${pageInfo.currentPage-1};
	var totalResult = ${pageInfo.totalResult};
	function initPager(){
		$("#Pagination").pagination(totalResult, {
            callback: function(new_page_index, pagination_container){
            	var oldLocation = location.href;
            	var pa = "currentPage=" + (new_page_index+1);
        		var shoC = "showCount=" + showCount;
            	var index = oldLocation.lastIndexOf("?");
            	if (index == -1){
            		location.href = oldLocation + "?" + pa + "&" + shoC;
            	}else if (oldLocation.indexOf("currentPage") == -1){
            		location.href = oldLocation + "&" + pa;
            	}else if (oldLocation.indexOf("showCount") == -1){
            		location.href = oldLocation + "&" + shoC;
            	}else{
            		var temp = oldLocation.replace(/currentPage=\d+/, pa);
					var newLocation = temp.replace(/showCount=\d+/, shoC);
            		location.href = newLocation;
            	}
            	return false;
            },
            items_per_page:showCount, 
            load_first_page:false,
            prev_text:'上一页',
            next_text:'下一页',
            ellipse_text:'...',
            num_edge_entries:1,
            num_display_entries:5,
            current_page:currentPage,
        });
	}
		
		/*添加*/
		function type_add(title,url){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		}
		/*重置*/
		function type_reset(url){
			window.location = url;
		}
		
		/*编辑*/
		function type_edit(obj,id,w,h){
			var edit_page = "<%=path%>/backstage/type-add-pre?id="+id;
			layer_show("编辑",edit_page,w,h);
		}
		/*删除*/
		function type_disable(obj,id){
			layer.confirm('确认删除？', {
				btn: ['确认','取消'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : "<%=path%>/backstage/type-disable",
					data : "id=" + id,
					error : function() {
						layer.msg('操作失败', {icon:5,time:1000});
					},
					success : function(msg) {
						layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
						$(obj).parents("body").find(".btn-refresh").click();
					}
				});
			},
			function(){
				layer.msg('未删除', {icon:5,time:1000});
			});	
		}
		/*审核*/
		function shop_enable(obj,id){
			layer.confirm('审核商户？', {
				btn: ['通过','不通过'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : "<%=path%>/backstage/shop-enable",
					data : "c_id=" + id,
					error : function() {
						layer.msg('操作失败', {icon:5,time:1000});
					},
					success : function(msg) {
						$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已审核</span>');
						$(obj).remove();
						layer.msg('已审核' + msg.information, {icon:6,time:1000});
					}
				});
			},
			function(){
				layer.msg('未通过', {icon:5,time:1000});
			});	
		}

		/*图片-下架*/
		function product_stop(obj,id){
			layer.confirm('确认要下架吗？',function(index){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,id)" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
				$(obj).remove();
				layer.msg('已下架!',{icon: 5,time:1000});
			});
		}
		
var type1;
var type2;	
function firstChange(theSelect){
			var typeId = theSelect.value;

			if (!type2){
				$.ajax({
					type:"post",
					async:false,
					url:"<%=path%>/backstage/get-types",
					data : {level:2,isZiYing:false},
					success : function(msg){
						type2 = msg;
					}
					});
				}
			var options = "<option value='-1'>--中类--</option>";
			for (var i = 0; i < type2.length; i++){
				if (typeId == type2[i].cBelong){
					var aOption = "<option value='"+type2[i].cCode+"' >"+type2[i].cName+"</option>"
					options += aOption; 
				}
			}
			$("#type2").html(options);
		}

	</script>
</body>
</html>